﻿function mycarousel_initCallback(carousel) {
    //与number图片绑定事件
    //    jQuery('#numberContainer img').click(function() {
    //        //carousel.scroll($(this).id);
    //        var index = $(this).attr("id").substring(5,6);
    //        var id = parseInt(index);
    //        console.log(id);
    //        carousel.scroll(id);
    //        return false;
    //    });
}

function mycarousel_itemLoadCallback(carousel, state) {
    if (state != 'init') return;

    $.getJSON('solutions/topn.ashx?n=6',
    function(data) {
        for (i = 0; i < data.length; i++) {
            var html = '<a href="solutions/detail.aspx?id=' + data[i].ID + '"><img src="file/solutions/thumbnail/' + data[i].IMAGE + '" width="166" height="109" alt=""  />' + data[i].NAME + '</a>';
            carousel.add(i + 1, html);
        }
        carousel.size(data.length);
    });
}

function mycarousel_itemFirstInCallback(carousel, item, idx, state) {
    idx = idx - 1;
    var acindex = idx % 6;
    if (acindex < 0) {
        acindex += 6;
    }

    $('#numberContainer img').each(function(index, obj) {
        if (index == acindex) {
            obj.src = "img/pic_0" + (index + 1) + "_1.png";
        }
        else {
            obj.src = "img/pic_0" + (index + 1) + "_2.png";
        }
    });
}

jQuery(document).ready(function() {
    //解决方案
    jQuery('#mycarousel').jcarousel({
        scroll: 1,
        wrap: 'circular',
        initCallback: mycarousel_initCallback,
        itemLoadCallback: mycarousel_itemLoadCallback,
        itemFirstInCallback: mycarousel_itemFirstInCallback
    });

    //系统产品
    $.getJSON('systemproduct/topn.ashx?n=10',
    function(data) {
        var html = [];
        for (i = 0; i < data.length; i++) {
            html.push('<li><a href="systemproduct/detail.aspx?id=' + data[i].ID + '">' + data[i].NAME + '</a></li>');
        }

        $('#systemProductList').html(html.join(''));
    });

    //数据产品
    $.getJSON('dataproduct/topn.ashx?n=10',
    function(data) {
        var html = [];
        for (i = 0; i < data.length; i++) {
            html.push('<li><a href="dataproduct/detail.aspx?id=' + data[i].ID + '">' + data[i].NAME + '</a></li>');
        }
        $('#dataProductList').html(html.join(''));
    });

    //行业新闻
    $.getJSON('news/topn.ashx?n=5',
    function(data) {
        var html = [];
        for (i = 0; i < data.length; i++) {
            var time = data[i].TIME;
            var newsdate = new Date(time.substring(0, 10));
            var day = (new Date() - newsdate) / (1000 * 60 * 60 * 24);
            if (day <= 1) {
                html.push('<li><a href="news/detail.aspx?id=' + data[i].ID + '">' + data[i].NAME + '</a><img src="img/pic_new.png" /></a><span class="newsdate">[' + time.substring(5, 10) + ']</span> </li>');
            } else {
                html.push('<li><a href="news/detail.aspx?id=' + data[i].ID + '">' + data[i].NAME + '</a></a><span class="newsdate">[' + time.substring(5, 10) + ']</span> </li>');
            }
        }

        $('#newsList').html(html.join(''));
    });

    //总排行榜
    $.getJSON('topn.ashx?n=10',
    function(data) {
        var html = [];
        for (i = 0; i < data.length; i++) {
            var ptype = "";
            if(data[i].PTYPE == 1){
                ptype = "solutions";
            }else if(data[i].PTYPE == 2){
                ptype = "systemproduct";
            }else if(data[i].PTYPE == 3){
                ptype = "dataproduct";
            }else if(data[i].PTYPE == 4){
                ptype = "news";
            }
        
            html.push('<li class="paihang' + (i + 1) + '"><a href="' + ptype + '/detail.aspx?id=' + data[i].ID + '">' + data[i].NAME + '</a></li>');
        }
        $('#paihangList').html(html.join(''));
    });
});